package cn.itlaobing.eshop.dao;

import cn.itlaobing.eshop.entity.Userinfo;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;

import java.sql.SQLException;

/**
 * @Description:
 * @Author: WangDong
 * @Date: 2017/11/14 21:24
 */
public class UserDao extends BaseDao{

    public Userinfo findByUser(String account, String password) throws SQLException {
        QueryRunner queryRunner=new QueryRunner(this.getDataSource());
        String sql="select * from userinfo where userName=? and userPass=?";
        BeanHandler<Userinfo> beanHandler=new BeanHandler<Userinfo>(Userinfo.class);
        return queryRunner.query(sql,beanHandler,account,password);
    }
    public int register(Userinfo userinfo) throws SQLException {
        QueryRunner queryRunner=new QueryRunner(this.getDataSource());
        String sql="INSERT INTO userinfo (userName,userPass)VALUE(?,?)";
        BeanHandler<Userinfo> beanHandler=new BeanHandler<Userinfo>(Userinfo.class);
        return queryRunner.update(sql,beanHandler,userinfo.getUsername(),userinfo.getUserpass());
    }

}
